Add ostree_ensure_repo_writable()
authorMatthew Barnes <mbarnes@redhat.com>
Fri, 16 Jan 2015 15:04:18 +0000 (10:04 -0500)
committerColin Walters <walters@verbum.org>
Wed, 25 Mar 2015 21:24:05 +0000 (17:24 -0400)
Commands that need to write files within the repo directory can call
this early to ensure the directory is writable for the current user.
If not, it fails with a helpful "You need to be root to perform this
command" message.

src/ostree/ot-main.c
src/ostree/ot-main.h

index c48a03c50582f8a96286c230a8b632b6d039efb4..94d29ca6a947ed1d2f84714a4d242a2e5a68845d 100644 (file)
@@ -360,3 +360,17 @@ ostree_admin_option_context_parse (GOptionContext *context,
 out:
   return success;
 }
+
+gboolean
+ostree_ensure_repo_writable (OstreeRepo *repo,
+                             GError **error)
+{
+  gboolean ret;
+
+  ret = ostree_repo_is_writable (repo, error);
+
+  g_prefix_error (error, "Cannot write to repository: ");
+
+  return ret;
+}
+
index 5f31b240728a26e8747ce01e35ead227bd22977f..659727f38aa7a65d5025868f73da9bb87de735ca 100644 (file)
@@ -51,3 +51,5 @@ gboolean ostree_admin_option_context_parse (GOptionContext *context,
                                             int *argc, char ***argv,
                                             OstreeSysroot **out_sysroot,
                                             GCancellable *cancellable, GError **error);
+
+gboolean ostree_ensure_repo_writable (OstreeRepo *repo, GError **error);